ARD2  1.00 for Rev B. Hardware
Airbag Reference Demonstrator using MPC5604P
HAL.c File Reference

Abstraction layer to be used for MPC5604P in an airbag. Upper layers shall make requests through this file to avoid dependencies in the application. More...

#include "derivative.h"
#include "Compile_Options.h"
#include "ADC.h"
#include "CRC.h"
#include "DSPI.h"
#include "EDMA.h"
#include "FCU.h"
#include "LIN_UART.h"
#include "ME.h"
#include "PIT.h"
#include "SIU.h"
#include "SWT.h"
#include "CGM.h"
#include "CG147.h"
#include "HAL.h"
#include "IntcInterrupts.h"
#include "Exceptions.h"
#include "Maildelivery.h"
#include "MailScheduler.h"

Functions

uint8_t u8fnMCUInit (void)
 Top-level initialization for Pictus. Takes care of all pins, peripherals, etc.
uint8_t u8fnInitPeripherals (void)
 Installs power-mode configurations for all peripherals, and then configures each peripheral for a particular power-mode as described in tISRConfig.
void vfnInitInterrupts (void)
 This function will route interrupt vectors to their routines as described by tISRConfig. It shall be called at startup and never again.
void vfnInitDSPI (void)
 This function will configure all DSPIs according to existing config tables u8fnConfigDSPIGeneral & cau32DefaultDSPIPresetConfig.
void vfnInitADC (void)
 This function will configure ADC0 for continuous conversions and will start it. It will run in parallel to the core after calling this routine.
void vfnInitSCI (void)
 This function will configure all SCIs according to existing config table cau32DefaultLINUARTConfig.
void vfnOutputPinInit (void)
 Will place output pins either in a high or low state according to a default table.
void vfnInputPadInit (void)
 Will route inputs to the correct modules using pre-established table.
void vfnInitDMAMux (uint8_t *pu8DMAMuxSettings, uint8_t u8Size)
 Initializes DMAMux.
uint8_t u8fnDelay (const uint32_t cu32TimeBase, uint16_t u16Cycles)
 This function uses PIT to create a delay. It responds to the following formula: delay = (Fbus / u32TimeBase) * u16Cycles.
uint8_t u8fnRawADCToDegreesCelsius (const uint16_t u16RawCounts)
 Converts Raw ADC counts to equivalent degrees celsius.
uint8_t u8fnRawADCToOutput (const uint16_t u16RawCounts)
 Converts Raw ADC counts to equivalent voltage * 10.
void vfnLaunchFCU (void)
 Launches the fault collection unit with configuration described by cau32FCUConfig.
uint8_t u8fnInitPostalService (const uint8_t cu8Enable)
 Calls all init functions to have a working messaging system.
uint8_t u8fnLaunchScheduler (const uint8_t cu8Enable)
 Launches scheduler using DSPI0 as instance.
void vfnTransferADCResults (uint8_t u8Instance, uint16_t *pu16Destination, uint16_t u16Size)
 Configures a dedicated DMA channel to transfer ongoing ADC conversions to a particular memory location.
void vfnEnterLowPowerMode (void)
 Takes the system into a non-operational low power mode.

Variables

const uint32_t cau32ADCConfig []
const uint32_t cau32FCUConfig []

Detailed Description

Abstraction layer to be used for MPC5604P in an airbag. Upper layers shall make requests through this file to avoid dependencies in the application.

Copyright (c) 2011 Freescale Semiconductor Freescale Confidential Proprietary

Author:
Freescale Semiconductor
SASD Automotive
R11515
Version:
Date:
Warning:
(If needed)

History:


Function Documentation

uint8_t u8fnDelay ( const uint32_t  cu32TimeBase,
uint16_t  u16Cycles 
)

This function uses PIT to create a delay. It responds to the following formula: delay = (Fbus / u32TimeBase) * u16Cycles.

Parameters:
cu32TimeBase,:divisor of clock
u16Cycles,:Multiplier.
Returns:
CLEAR if all went ok; PIT_SELECTED_CH_DOESNT_EXIST if the selected PIT channel does not exist; PIT_TIMER_NOT_RUNNING if there was a time-out.
uint8_t u8fnInitPeripherals ( void  )

Installs power-mode configurations for all peripherals, and then configures each peripheral for a particular power-mode as described in tISRConfig.

Parameters:
None.
Returns:
u8Status: Clear if successful, ME_INVALID_INDEX if a peripheral index within tISRConfig is out of spec.
uint8_t u8fnInitPostalService ( const uint8_t  cu8Enable)

Calls all init functions to have a working messaging system.

Parameters:
cu8Enable,:If non-zero, it will initialize the messaging system, including connections to SPI. If zero, it will disable the messaging system, disconnecting the DMA service from SPI and restoring its typical capability.
Returns:
u8Status: Always clear.
Warning:
This function hard-codes the postal service to DSPI0.
uint8_t u8fnLaunchScheduler ( const uint8_t  cu8Enable)

Launches scheduler using DSPI0 as instance.

Parameters:
cu8Enable,:If non-zero, launches the scheduler, otherwise stops it.
Returns:
PIT_INVALID_CH in case the selected PIT channels for the scheduler are invalid; CLEAR otherwise. This should never occur if the application is well designed.
uint8_t u8fnMCUInit ( void  )

Top-level initialization for Pictus. Takes care of all pins, peripherals, etc.

Parameters:
None.
Returns:
u8Status: Clear if all ok, PERIPHERALS_NOT_INITIALIZED if peripherals were not correctly installed; SWT_NOT_INITIALIZED if the watchdog was not correctly initialized; PLL_ERROR if the PLL configuration had errors; RUN_MODE_NOT_STARTED if the PLL did not lock or the system was not able to pass to the established RUN mode,
uint8_t u8fnRawADCToDegreesCelsius ( const uint16_t  u16RawCounts)

Converts Raw ADC counts to equivalent degrees celsius.

Parameters:
u16RawCounts,:10-bit raw ADC count for temperature. u8Temp: Temperature rounded up to closest degree celsius.
uint8_t u8fnRawADCToOutput ( const uint16_t  u16RawCounts)

Converts Raw ADC counts to equivalent voltage * 10.

Parameters:
u16RawCounts,:10-bit raw ADC counts.
Returns:
u8Voltage: Approximate voltage value for the RAW ADC value * 10.
void vfnEnterLowPowerMode ( void  )

Takes the system into a non-operational low power mode.

Parameters:
None
Returns:
Void.
void vfnInitADC ( void  )

This function will configure ADC0 for continuous conversions and will start it. It will run in parallel to the core after calling this routine.

Parameters:
None.
Returns:
void.
Warning:
This routine configures ADC_TO_AOUT_CH for continuous readings due to the existing HW configuration. This may need to change if HW changes are present.
void vfnInitDMAMux ( uint8_t *  pu8DMAMuxSettings,
uint8_t  u8Size 
)

Initializes DMAMux.

Parameters:
pu8DMAMuxSettings,:Pointer to DMA settings
u8Size,:Size of table
Returns:
void.
void vfnInitDSPI ( void  )

This function will configure all DSPIs according to existing config tables u8fnConfigDSPIGeneral & cau32DefaultDSPIPresetConfig.

Parameters:
None.
Returns:
void.
void vfnInitInterrupts ( void  )

This function will route interrupt vectors to their routines as described by tISRConfig. It shall be called at startup and never again.

Parameters:
None.
Returns:
void.
void vfnInitSCI ( void  )

This function will configure all SCIs according to existing config table cau32DefaultLINUARTConfig.

Parameters:
None.
Returns:
void.
void vfnInputPadInit ( void  )

Will route inputs to the correct modules using pre-established table.

Parameters:
None.
Returns:
void.
void vfnLaunchFCU ( void  )

Launches the fault collection unit with configuration described by cau32FCUConfig.

Parameters:
None.
Returns:
void.
void vfnOutputPinInit ( void  )

Will place output pins either in a high or low state according to a default table.

Parameters:
None.
Returns:
void.
void vfnTransferADCResults ( uint8_t  u8Instance,
uint16_t *  pu16Destination,
uint16_t  u16Size 
)

Configures a dedicated DMA channel to transfer ongoing ADC conversions to a particular memory location.

Parameters:
u8Instance,:0 or 1, depending on which ADC instance needs to be read.
pu16Destination,:pointer to location where the results shall be placed.
u16Size,:Amount of ADC readings to transfer.
Returns:
Void.

Variable Documentation

const uint32_t cau32ADCConfig[]
Initial value:
{
  
  (ADC_DATA_CAN_BE_OVERWRITTEN | ADC_DATA_IS_ALIGNED_RIGHT
      | ADC_IS_IN_SCAN_MODE | ADC_CTU_IS_OFF | ADC_AUTOCLOCK_OFF_EN
      | ADC_EO_CTU_CONV_ISR_DIS | ADC_EO_INJ_CHAN_CONV_ISR_DIS
      | ADC_EO_INJ_CHAIN_CONV_ISR_DIS | ADC_EO_CHAN_CONV_ISR_DIS
      | ADC_EO_CHAIN_CONV_ISR_DIS | ADC_DMA_CLEARED_ON_ACK | ADC_DMA_EN
      | ADC_IS_CLOCKING_HALF_SPEED | ADC_PR_LSB_NO_ROUNDING
      | ADC_LOW_SPEED_CONFIG),
  
  (ADC_DATA_CAN_BE_OVERWRITTEN | ADC_DATA_IS_ALIGNED_RIGHT
      | ADC_IS_IN_SCAN_MODE | ADC_CTU_IS_OFF | ADC_AUTOCLOCK_OFF_EN
      | ADC_EO_CTU_CONV_ISR_DIS | ADC_EO_INJ_CHAN_CONV_ISR_DIS
      | ADC_EO_INJ_CHAIN_CONV_ISR_DIS | ADC_EO_CHAN_CONV_ISR_DIS
      | ADC_EO_CHAIN_CONV_ISR_DIS | ADC_DMA_CLEARED_ON_ACK | ADC_DMA_DIS
      | ADC_IS_CLOCKING_HALF_SPEED | ADC_PR_LSB_NO_ROUNDING
      | ADC_LOW_SPEED_CONFIG) }

Default ADC configuration per instance set at startup

const uint32_t cau32FCUConfig[]
Initial value:
 
{
  
  FCU_TIMEOUT(FCU_4MS_TIMEOUT),
  
  
  (FCU_TES0_ENABLED | FCU_TES1_ENABLED | FCU_TES2_ENABLED | FCU_TES3_ENABLED
  | FCU_TES4_ENABLED | FCU_ESF0_ENABLED | FCU_ESF1_ENABLED | FCU_ESF2_ENABLED
  | FCU_ESF3_ENABLED | FCU_ESF4_ENABLED | 
  FCU_ENABLE_CH(FCU_CORE_CHECKSTOP_MODE_ENTERED | FCU_CORE_RESET | 
                FCU_LOSS_OF_XTAL | FCU_LOSS_OF_PLL0_LOCK | 
                FCU_FREQ0_OUT_OF_RANGE | FCU_LOSS_OF_PLL1_LOCK | 
                FCU_FREQ1_OUT_OF_RANGE | FCU_FLASH_FATAL_ERROR | 
                FCU_WATCHDOG_RESET | FCU_JTAG_RESET | FCU_POWER_COMPARATOR_ERROR 
                | FCU_LVD_4_5 | FCU_LVD_2_7_VREG | FCU_LVD_2_7_FLASH | 
                FCU_LVD_2_7_I_0 | FCU_LVD_1_2_DIG)),
  
  (FCU_TIMEOUT_CH(FCU_CORE_CHECKSTOP_MODE_ENTERED |  
                FCU_LOSS_OF_XTAL | FCU_LOSS_OF_PLL0_LOCK | 
                FCU_FREQ0_OUT_OF_RANGE | FCU_LOSS_OF_PLL1_LOCK | 
                FCU_FREQ1_OUT_OF_RANGE | FCU_FLASH_FATAL_ERROR | 
                FCU_POWER_COMPARATOR_ERROR 
                | FCU_LVD_4_5 | FCU_LVD_2_7_VREG | FCU_LVD_2_7_FLASH | 
                FCU_LVD_2_7_I_0 | FCU_LVD_1_2_DIG) | FCU_NO_TEST_MODE | 
                FCU_OUTPUT0_INV_POL | FCU_OUTPUT_IS_TIME_SWITCH | 
                FCU_OUTPUT_FREQ(7u))              
}

This variable contains the settings used for the fault collection unit